﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Catsland.Core;
using System.ComponentModel;
using Catsland.Editor;

namespace Catsland.CatsPlugin
{
    class ModelComponent : CatComponent
    {
        CatsModel m_model;
        [CategoryAttribute("Basic"), 
            EditorAttribute(typeof(PropertyGridModelSelector), 
            typeof(System.Drawing.Design.UITypeEditor))]
        public CatsModel Model
        {
            set
            {
                m_model = value;
            }
            get
            {
                return m_model;
            }
        }

        public ModelComponent(GameObject gameObject) 
            : base(gameObject)
        {
        }

        public override CatComponent CloneComponent(GameObject gameObject)
        {
            ModelComponent modelComponent = new ModelComponent(gameObject);
            modelComponent.Model = Model;
            return modelComponent;
        }

        public override bool SaveToNode(XmlNode node, XmlDocument doc)
        {
            XmlElement modelComponent = doc.CreateElement(typeof(ModelComponent).Name);
            node.AppendChild(modelComponent);

            modelComponent.SetAttribute("name", Model._name);

            return true;
        }

        public override void ConfigureFromNode(XmlElement node, Scene scene, GameObject gameObject)
        {
            base.ConfigureFromNode(node, scene, gameObject);
            Model = scene._modelList.GetModel(node.GetAttribute("name"));
        }
    }
}
